package com.dao;

import java.sql.ResultSet;

import util.DBUtil;

import com.bean.Admin;

public class AdminDao {
	String sql="";
	ResultSet rs = null;
	
	public int loginByAdmin(Admin admin){
		sql = "select * from admin where username='"+admin.getUsername()+"'";
		int i = 0;
		try{
			DBUtil.getConnection();
		} catch(Exception e){
			e.printStackTrace();
		}
		rs = DBUtil.executeQuery(sql);
		try{
			if(rs.next()){
				String password = rs.getString("password");
				if(admin.getPassword().equals(password))
				{
					i = 1;
				}else{
					i = -1;
				}
				
			}else{
				i = -1;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally{
			DBUtil.close();
		}
		return i;
	}

}
